<?php   
		 $dom = new DomDocument('1.0');
        $dom->load('stocks.xml');
		$root = $dom->lastChild;
        srand(time());
        foreach ($root->childNodes As $child)
        {
            $RandomNumber = (rand()%100);
            if ($child->nodeType == 1) 
            {
				foreach ($child->childNodes As $subchild)
				{
                if ($subchild->nodeName == "price")
                {
                    $value = $subchild->textContent;
                    $RandomPrice = (rand()%$value);
                    $RandomPrice = $RandomPrice / 10;
                    
                    $direction = "";
                    if (($RandomNumber % 2) == 1)
                    {
                        $direction = "Down";
                        $value = $value - $RandomPrice;
                       
                    }
                    else
                    {
                         $direction = "Up";
                         $value = $value + $RandomPrice;
                    }
                        
					     
					     $textNode = $dom->createTextNode($value);
					     $subchild->nodeValue = "";
                         $newchild = $subchild->appendChild($textNode);
                }

	            if ($subchild->nodeName == "direction")
                {
						 $textNode = $dom->createTextNode($direction);
						 $subchild->nodeValue = "";
                         $newchild = $subchild->appendChild($textNode);
                }
			}
            }
        }
    $dom->save('stocks.xml');
?>
